//
//  CompanyInfoImgCell.m
//  LogisticsSupplier
//
//  Created by 吕晶 on 2020/8/31.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "CompanyInfoImgCell.h"

@interface CompanyInfoImgCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UILabel *xingLab;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UIImageView *iconImgView;
@property (nonatomic, strong) UILabel *lineLab;
@property (nonatomic, strong) UIButton *clickBtn;

@end

@implementation CompanyInfoImgCell

+ (instancetype)CompanyInfoImgCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"CompanyInfoImgCell";
    CompanyInfoImgCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[CompanyInfoImgCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = Color_backgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenW, 60)];
        self.bgView.backgroundColor = HexColor(0xffffff);
        [self.contentView addSubview:self.bgView];
        
        self.lineLab = [[UILabel alloc] initWithFrame:CGRectMake(10, self.bgView.nim_height - 1, self.bgView.nim_width - 20, 1)];
        self.lineLab.backgroundColor = Color_backgroundColor;
        [self.bgView addSubview:self.lineLab];
        
        self.xingLab = [UILabel new];
        self.xingLab.text = @"*";
        self.xingLab.font = [UIFont systemFontOfSize:14];
        [self.xingLab sizeToFit];
        self.xingLab.nim_left = 10;
        self.xingLab.nim_top = 20;
        self.xingLab.textColor = HexColor(0xF35959);
        [self.bgView addSubview:self.xingLab];
        
        self.titleLab = [[UILabel alloc] initWithFrame:CGRectMake(self.xingLab.nim_right, 22.5, 120, 15)];
        self.titleLab.font = [UIFont systemFontOfSize:14];
        self.titleLab.textColor = HexColor(0x2B2C44);
        [self.bgView addSubview:self.titleLab];
        
        self.iconImgView = [[UIImageView alloc] initWithFrame:CGRectMake(self.bgView.nim_width - 10 - 48, 6, 48, 48)];
        self.iconImgView.backgroundColor = HexColor(0x5780D9);
        self.iconImgView.layer.masksToBounds = YES;
        self.iconImgView.layer.cornerRadius = 4;
        [self.bgView addSubview:self.iconImgView];
        
        self.height = self.bgView.nim_bottom;
        
        self.clickBtn = [[UIButton alloc] initWithFrame:self.bgView.frame];
        [self.clickBtn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
        self.clickBtn.hidden = YES;
        [self.contentView addSubview:self.clickBtn];
    }
    return self;
}

- (void)btnClick {
    if (self.clickBlock) {
        self.clickBlock();
    }
}

-(void)setIsMust:(BOOL)isMust {
    _isMust = isMust;
    self.xingLab.hidden = !isMust;
}

-(void)setTitleText:(NSString *)titleText {
    _titleText = titleText;
    self.titleLab.text = titleText;
}

-(void)setIconUrl:(NSString *)iconUrl {
    _iconUrl = iconUrl;
    [self.iconImgView sd_setImageWithURL:[NSURL URLWithString:iconUrl]];
}

-(void)setShowLine:(BOOL)showLine {
    _showLine = showLine;
    self.lineLab.hidden = !showLine;
}

-(void)setCanClick:(BOOL)canClick {
    _canClick = canClick;
    self.clickBtn.hidden = !canClick;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
